package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.domain.ClientDevelop;
import org.ahuanlien.crm.query.ClientDevelopQueryObject;
import org.ahuanlien.crm.service.IClientDevelopService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("clientDevelop")
public class ClientDevelopController {

	@Autowired
	private IClientDevelopService clientDevelopService;

	//潜在客户开发计划页面
	@RequestMapping("develop")
	@RequiresPermissions(value = {"clientDevelop:develop", "潜在客户开发计划页面"}, logical = Logical.OR)
	public String develop() {
		return "clientDevelop/develop";
	}

	//正式客户跟进计划页面
	@RequestMapping("followUp")
	@RequiresPermissions(value = {"clientDevelop:followUp", "正式客户跟进计划页面"}, logical = Logical.OR)
	public String followUp() {
		return "clientDevelop/followUp";
	}

	@RequestMapping("query")
	@RequiresPermissions(value = {"clientDevelop:query", "开发计划/客户跟进列表"}, logical = Logical.OR)
	@ResponseBody
	public PageResult query(ClientDevelopQueryObject qo) {
		PageResult result = clientDevelopService.Query(qo);
		return result;
	}

	@RequestMapping("saveOrUpdate")
	@RequiresPermissions(value = {"clientDevelop:saveOrUpdate", "开发计划/客户跟进新增/编辑"}, logical = Logical.OR)
	@ResponseBody
	public JSONResult saveOrUpdate(ClientDevelop record) {
		try {
			clientDevelopService.saveOrUpdate(record);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}

	@RequestMapping("deleteRecordById")
	@RequiresPermissions(value = {"clientDevelop:deleteRecordById", "开发计划/客户跟进删除"}, logical = Logical.OR)
	@ResponseBody
	public JSONResult deleteRecordById(Long id) {
		try {
			clientDevelopService.deleteRecordById(id);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}

	@RequestMapping("changeResult")
	@RequiresPermissions(value = {"clientDevelop:changeResult", "开发计划/客户跟进修改标记"}, logical = Logical.OR)
	@ResponseBody
	public JSONResult changeResult(Long id, Long result) {
		try {
			clientDevelopService.changeResult(id,result);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}
}
